home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / gcc263-utildoc.lha / gnu / man / man1 / sort.1 < prev    next >
Encoding:
Text File  |  1994-12-19  |  9.5 KB  |  265 lines

  1.  
  2.  
  3.  
  4. SORT(1L)                                                 SORT(1L)
  5.  
  6.  
  7. NNAAMMEE
  8.        sort - sort lines of text files
  9.  
  10. SSYYNNOOPPSSIISS
  11.        ssoorrtt  [-cmus] [-t separator] [-o output-file] [-T tempdir]
  12.        [-bdfiMnr] [+POS1 [-POS2]] [-k POS1[,POS2]] [file...]
  13.        ssoorrtt {--help,--version}
  14.  
  15. DDEESSCCRRIIPPTTIIOONN
  16.        This manual page documents the GNU version of ssoorrtt.   ssoorrtt
  17.        sorts,  merges,  or  compares all the lines from the given
  18.        files, or the standard input if no  files  are  given.   A
  19.        file  name  of `-' means standard input.  By default, ssoorrtt
  20.        writes the results to the standard output.
  21.  
  22.        ssoorrtt has three modes of  operation:  sort  (the  default),
  23.        merge,  and  check  for sortedness.  The following options
  24.        change the operation mode:
  25.  
  26.        _-_c     Check whether the given files are  already  sorted:
  27.               if  they are not all sorted, print an error message
  28.               and exit with a status of 1.
  29.  
  30.        _-_m     Merge the given files by sorting them as  a  group.
  31.               Each  input  file  should  already  be individually
  32.               sorted.  It always works to sort instead of  merge;
  33.               merging  is  provided  because it is faster, in the
  34.               case where it works.
  35.  
  36.        A pair of lines is compared as follows: if any key  fields
  37.        have been specified, ssoorrtt compares each pair of fields, in
  38.        the order specified on the command line, according to  the
  39.        associated  ordering  options, until a difference is found
  40.        or no fields are left.
  41.  
  42.        If any of the global options _M_b_d_f_i_n_r are given but no  key
  43.        fields  are  specified,  ssoorrtt  compares  the  entire lines
  44.        according to the global options.
  45.  
  46.        Finally, as a last resort when all keys compare equal  (or
  47.        if  no  ordering options were specified at all), ssoorrtt com-
  48.        pares  the  lines  byte  by  byte  in  machine   collating
  49.        sequence.  The last resort comparison honors the _-_r global
  50.        option.  The _-_s (stable) option disables this  last-resort
  51.        comparison so that lines in which all fields compare equal
  52.        are left in their original relative order.  If  no  fields
  53.        or global options are specified, _-_s has no effect.
  54.  
  55.        GNU  ssoorrtt  has  no limits on input line length or restric-
  56.        tions on bytes allowed within lines.  In addition, if  the
  57.        final  byte  of  an  input file is not a newline, GNU ssoorrtt
  58.        silently supplies one.
  59.  
  60.        If the environment variable TTMMPPDDIIRR is set, ssoorrtt uses it as
  61.  
  62.  
  63.  
  64. FSF                     GNU Text Utilities                      1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. SORT(1L)                                                 SORT(1L)
  71.  
  72.  
  73.        the  directory  in which to put temporary files instead of
  74.        the default, /tmp.  The _-_T _t_e_m_p_d_i_r option is  another  way
  75.        to  select the directory for temporary files; it overrides
  76.        the environment variable.
  77.  
  78.        The following options affect the ordering of output lines.
  79.        They  may  be  specified globally or as part of a specific
  80.        key field.  If no key fields are specified, global options
  81.        apply  to comparison of entire lines; otherwise the global
  82.        options are inherited by key fields that  do  not  specify
  83.        any special options of their own.
  84.  
  85.        _-_b     Ignore  leading  blanks  when  finding sort keys in
  86.               each line.
  87.  
  88.        _-_d     Sort in `phone directory' order: ignore all charac-
  89.               ters  except  letters, digits and blanks when sort-
  90.               ing.
  91.  
  92.        _-_f     Fold lower  case  characters  into  the  equivalent
  93.               upper  case  characters  when  sorting so that, for
  94.               example, `b' is sorted the same way `B' is.
  95.  
  96.        _-_i     Ignore characters outside the ASCII range  040-0176
  97.               octal (inclusive) when sorting.
  98.  
  99.        _-_M     An  initial  string,  consisting  of  any amount of
  100.               white space, followed by three letters abbreviating
  101.               a  month name, is folded to UPPER case and compared
  102.               in the order `JAN' < `FEB' < ... < `DEC.'   Invalid
  103.               names compare low to valid names.
  104.  
  105.        _-_n     Compare  according  to  arithmetic value an initial
  106.               numeric string consisting of optional white  space,
  107.               an  optional  -  sign,  and  zero  or  more digits,
  108.               optionally followed by a decimal point and zero  or
  109.               more digits.
  110.  
  111.        _-_r     Reverse  the  result  of  comparison, so that lines
  112.               with greater key values appear earlier in the  out-
  113.               put instead of later.
  114.  
  115.        Other options are:
  116.  
  117.        _-_o _o_u_t_p_u_t_-_f_i_l_e
  118.               Write output to _o_u_t_p_u_t_-_f_i_l_e instead of to the stan-
  119.               dard output.  If _o_u_t_p_u_t_-_f_i_l_e is one  of  the  input
  120.               files,  ssoorrtt  copies  it to a temporary file before
  121.               sorting and writing the output to _o_u_t_p_u_t_-_f_i_l_e.
  122.  
  123.        _-_t _s_e_p_a_r_a_t_o_r
  124.               Use character _s_e_p_a_r_a_t_o_r as the field separator when
  125.               finding  the  sort  keys in each line.  By default,
  126.               fields are separated by the empty string between  a
  127.  
  128.  
  129.  
  130. FSF                     GNU Text Utilities                      2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. SORT(1L)                                                 SORT(1L)
  137.  
  138.  
  139.               non-whitespace  character  and a whitespace charac-
  140.               ter.  That is to say, given the input  line  `  foo
  141.               bar', ssoorrtt breaks it into fields ` foo' and ` bar'.
  142.               The field separator is not considered to be part of
  143.               either  the  field preceding or the field following
  144.               it.
  145.  
  146.        _-_u     For the default case or the _-_m option, only  output
  147.               the  first  of  a  sequence  of  lines that compare
  148.               equal.  For the _-_c option, check that  no  pair  of
  149.               consecutive lines compares equal.
  150.  
  151.        _+_P_O_S_1 _[_-_P_O_S_2_]
  152.               Specify  a field within each line to use as a sort-
  153.               ing key.  The field consists of the portion of  the
  154.               line starting at POS1 and up to (but not including)
  155.               POS2 (or to the end of the  line  if  POS2  is  not
  156.               given).   The  fields  and  character positions are
  157.               numbered starting with 0.
  158.  
  159.        _-_k _P_O_S_1_[_,_P_O_S_2_]
  160.               An alternate syntax for  specifying  sorting  keys.
  161.               The  fields  and  character  positions are numbered
  162.               starting with 1.
  163.  
  164.        A position has the form _f._c, where _f is the number of  the
  165.        field  to  use  and _c is the number of the first character
  166.        from the beginning of the field (for _+_p_o_s) or from the end
  167.        of  the previous field (for _-_p_o_s).  The ._c part of a posi-
  168.        tion may be omitted in which case it is taken  to  be  the
  169.        first  character  in the field.  If the _-_b option has been
  170.        given, the ._c part of a  field  specification  is  counted
  171.        from  the first nonblank character of the field (for _+_p_o_s)
  172.        or from the first nonblank character following the  previ-
  173.        ous field (for _-_p_o_s).
  174.  
  175.        A  _+_p_o_s  or  _-_p_o_s argument may also have any of the option
  176.        letters _M_b_d_f_i_n_r appended to it, in which case  the  global
  177.        ordering  options  are not used for that particular field.
  178.        The _-_b option may be independently attached to  either  or
  179.        both  of the _+_p_o_s and _-_p_o_s parts of a field specification,
  180.        and if it is inherited from the global options it will  be
  181.        attached  to  both.   If  a  _-_n or _-_M option is used, thus
  182.        implying a _-_b option, the _-_b option is taken to  apply  to
  183.        both  the  _+_p_o_s and the _-_p_o_s parts of a key specification.
  184.        Keys may span multiple fields.
  185.  
  186.        In addition, when GNU jjooiinn is  invoked  with  exactly  one
  187.        argument, the following options are recognized:
  188.  
  189.        _-_-_h_e_l_p Print  a  usage message on standard output and exit
  190.               successfully.
  191.  
  192.  
  193.  
  194.  
  195.  
  196. FSF                     GNU Text Utilities                      3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. SORT(1L)                                                 SORT(1L)
  203.  
  204.  
  205.        _-_-_v_e_r_s_i_o_n
  206.               Print version information on standard  output  then
  207.               exit successfully.
  208.  
  209. CCOOMMPPAATTIIBBIILLIITTYY
  210.        Historical (BSD and System V) implementations of ssoorrtt have
  211.        differed in their interpretation of some options, particu-
  212.        larly  _-_b,  _-_f, and _-_n.  GNU sort follows the POSIX behav-
  213.        ior, which is usually (but not always!) like the System  V
  214.        behavior.   According  to  POSIX  _-_n no longer implies _-_b.
  215.        For consistency, _-_M has been  changed  in  the  same  way.
  216.        This  may  affect  the  meaning  of character positions in
  217.        field specifications in obscure cases.  If this bites  you
  218.        the fix is to add an explicit _-_b.
  219.  
  220. BBUUGGSS
  221.        The  different  meaning  of  field  numbers  depending  on
  222.        whether _-_k is used is confusing.  It's all POSIX's  fault!
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262. FSF                     GNU Text Utilities                      4
  263.  
  264.  
  265.